<script>
export default {
	onLaunch: function(option) {
		uni.getSystemInfo({
				success(res) {
					// that.globalData.statusBarHeight = res.statusBarHeight;
					uni.setStorageSync('statusBarHeight', res.statusBarHeight);
				}
			})
		console.log('App Launch');
		if(option.query.icode){
			uni.setStorageSync('icode', option.query.icode);
		}
		// #ifdef APP-PLUS
		
		//APP更新
		let that = this
		uni.request({
			// url: 'http://yq.banmakuaipao.top/api/index/appUpdate',  
			url: 'http://rr4413.t1.nethhw188.com/api/index/appUpdate',  
			data: {
				'type':uni.getSystemInfoSync().platform == 'android' ? '1': '2'
			},  
			success: (res) => {
				plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {   //这里用 plus.runtime.getProperty() 来获取相关信息。
					that.$store.commit('state_version',widgetInfo.version)
					
					let used_version = widgetInfo.version.split('.').join('')
					let news_version =  res.data.data.versionCode.split('.').join('')
					
					if(used_version != news_version){
						let update_mode
						Number(news_version) - Number(used_version) >= 1000 ? update_mode = true : update_mode = false
						if(res.data.data.ishot == 1){ //是否强制更新
							uni.showModal({
								title: '提示',
								content: '检测到新版本，需要更新后才能使用',
								success: function (ref) {
									toUpdate(res.data.data,update_mode)
								}
							});									
						}else if(res.data.data.ishot == 0){
							uni.showModal({
								title: '提示',
								content: '检测到新版本，是否确定更新？',
								success: function (ref) {
									if (ref.confirm) {
										toUpdate(res.data.data,update_mode)
									} else if (ref.cancel) {
										// console.log('用户点击取消');
									}
								}
							});
						}
					}
				});
			}  
		})
		
		let toUpdate = function(data,update_mode){
			if(update_mode){
				plus.runtime.openURL(data.pkgUrl);
			}else{
				uni.showLoading({
					title: '下载中',
					mask:true
				});
				uni.downloadFile({
					url: data.wgtUrl,
					success: (downloadResult) => {
						uni.showLoading({
							title: '安装中',
							mask:true
						});
						if (downloadResult.statusCode === 200) {
							plus.runtime.install(downloadResult.tempFilePath, {
								force: true //强制安装
							}, function(e) {
								uni.hideLoading();
								plus.runtime.restart();
							}, function(e) {
								uni.hideLoading();
								console.log(e)
								console.log("安装文件失败！");  
							});
						}
					}
				});
			}
		}
		//APP更新
		 		 
		// #endif
		
		
	},
	globalData:{
		statusBarHeight:'',//手机顶部状态栏高度
	},
	onShow: function() {
		console.log('App Show');
	},
	onHide: function() {
		console.log('App Hide');
	}
};
</script>

<style lang="scss">
/* 引入官方样式 */
@import './common/uni.css';
/* @import './common/iconfont.css'; */
@import "uview-ui/index.scss";
/* 引入通用样式*/
@import './common/common.css';


page {
	background-color: #f3f3f3;
}
page,
.container {
	box-sizing: border-box;
}
.iconfont {
  font-family: "iconfont" !important;
  font-size: 16px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.icon-iconfonticonfonti2:before {
  content: "\e62c";
}

.icon-shangjiantou:before {
  content: "\e61e";
}
/* checkbox样式重置 */
uni-checkbox .uni-checkbox-input {
	height: 40upx;
	width: 40upx;
	border-radius: 50%;
}

uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked:before {
	color: #ffffff;
	position: absolute;
	font-size: 35upx;
}

uni-checkbox:not([disabled]) .uni-checkbox-input:hover {
	border-color: #d1d1d1;
}

uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
	background-color: #f81149;
}

/* 解决头条小程序组件内引入字体不生效的问题 */
/* #ifdef MP-TOUTIAO */
@font-face {
	font-family: uniicons;
	src: url('/static/uni.ttf');
}
/* #endif */
</style>
